package com.ruin.tech.ahri.controller;

import com.ruin.tech.ahri.model.dto.CalculatorDTO;
import com.ruin.tech.ahri.result.Result;
import com.ruin.tech.ahri.result.ResultFactory;
import com.ruin.tech.ahri.service.ICalculator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author: yuegc
 * @description: 房贷计算器
 * @create: 2019/12/13 11:42
 */
@Slf4j
@RestController
@RequestMapping("/calculator")
public class MortgageCalculatorController {
    @Resource
    ICalculator calculator;

    /***
     * @Description: 等额本息 
     * @Param: [calculatorDTO]
     * @return: com.ruin.tech.ahri.result.Result
     * @Author: yuegc
     * @Date: 2019/12/13 14:56:08
     */
    @PostMapping("/equalInstallmentsOfPrincipalAndInterest")
    public Result equalInstallmentsOfPrincipalAndInterest(@Valid @RequestBody CalculatorDTO calculatorDTO) {
        return ResultFactory.buildSuccessResult(calculator.equalInstallmentsOfPrincipalAndInterest(calculatorDTO));
    }

    /***
     * @Description: 等额本金
     * @Param: [calculatorDTO]
     * @return: com.ruin.tech.ahri.result.Result
     * @Author: yuegc
     * @Date: 2019/12/13 15:12:32
     */
    @PostMapping("/equivalentPrincipal")
    public Result equivalentPrincipal(@Valid @RequestBody CalculatorDTO calculatorDTO) {
        return ResultFactory.buildSuccessResult(calculator.equivalentPrincipal(calculatorDTO));
    }
}
